<template>
  <el-dialog
    :title="!dataForm.housesId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="楼盘名称" prop="housesName">
      <el-input v-model="dataForm.housesName" placeholder="楼盘名称"></el-input>
    </el-form-item>
    <el-form-item label="楼盘区域" prop="housesDistrict">
      <el-input v-model="dataForm.housesDistrict" placeholder="楼盘区域"></el-input>
    </el-form-item>
    <el-form-item label="楼盘价格" prop="housesPrice">
      <el-input v-model="dataForm.housesPrice" placeholder="楼盘价格"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="housesTime">
      <el-input v-model="dataForm.housesTime" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="楼盘排序" prop="housesSort">
      <el-input v-model="dataForm.housesSort" placeholder="楼盘排序"></el-input>
    </el-form-item>
    <el-form-item label="楼盘状态" prop="housesStatic">
      <el-input v-model="dataForm.housesStatic" placeholder="楼盘状态"></el-input>
    </el-form-item>
    <el-form-item label="楼盘省份" prop="housesProvince">
      <el-input v-model="dataForm.housesProvince" placeholder="楼盘省份"></el-input>
    </el-form-item>
    <el-form-item label="楼盘城市" prop="housesCity">
      <el-input v-model="dataForm.housesCity" placeholder="楼盘城市"></el-input>
    </el-form-item>
    <el-form-item label="楼盘区县" prop="housesCounty">
      <el-input v-model="dataForm.housesCounty" placeholder="楼盘区县"></el-input>
    </el-form-item>
    <el-form-item label="楼盘沙盘" prop="housesSand">
      <el-input v-model="dataForm.housesSand" placeholder="楼盘沙盘"></el-input>
    </el-form-item>
    <el-form-item label="楼盘地址" prop="housesSite">
      <el-input v-model="dataForm.housesSite" placeholder="楼盘地址"></el-input>
    </el-form-item>
    <el-form-item label="楼盘开盘时间" prop="housesOpeningTime">
      <el-input v-model="dataForm.housesOpeningTime" placeholder="楼盘开盘时间"></el-input>
    </el-form-item>
    <el-form-item label="售楼电话" prop="housesPhone">
      <el-input v-model="dataForm.housesPhone" placeholder="售楼电话"></el-input>
    </el-form-item>
    <el-form-item label="开发商" prop="developersName">
      <el-input v-model="dataForm.developersName" placeholder="开发商"></el-input>
    </el-form-item>
    <el-form-item label="购房红包" prop="housesRedpacket">
      <el-input v-model="dataForm.housesRedpacket" placeholder="购房红包"></el-input>
    </el-form-item>
    <el-form-item label="售楼处地址" prop="developersSite">
      <el-input v-model="dataForm.developersSite" placeholder="售楼处地址"></el-input>
    </el-form-item>
    <el-form-item label="交房时间" prop="housesCheckTime">
      <el-input v-model="dataForm.housesCheckTime" placeholder="交房时间"></el-input>
    </el-form-item>
    <el-form-item label="销售证号" prop="developersCertificate">
      <el-input v-model="dataForm.developersCertificate" placeholder="销售证号"></el-input>
    </el-form-item>
    <el-form-item label="地图坐标" prop="developersCoordinate">
      <el-input v-model="dataForm.developersCoordinate" placeholder="地图坐标"></el-input>
    </el-form-item>
    <el-form-item label="是否优惠" prop="housesDiscounts">
      <el-input v-model="dataForm.housesDiscounts" placeholder="是否优惠"></el-input>
    </el-form-item>
    <el-form-item label="装修情况id" prop="fitmentId">
      <el-input v-model="dataForm.fitmentId" placeholder="装修情况id"></el-input>
    </el-form-item>
    <el-form-item label="销售状态" prop="marketId">
      <el-input v-model="dataForm.marketId" placeholder="销售状态"></el-input>
    </el-form-item>
    <el-form-item label="类型id" prop="typeId">
      <el-input v-model="dataForm.typeId" placeholder="类型id"></el-input>
    </el-form-item>
    <el-form-item label="特色id" prop="featureId">
      <el-input v-model="dataForm.featureId" placeholder="特色id"></el-input>
    </el-form-item>
    <el-form-item label="推荐id" prop="recommendId">
      <el-input v-model="dataForm.recommendId" placeholder="推荐id"></el-input>
    </el-form-item>
    <el-form-item label="缩略图" prop="housesImg">
      <el-input v-model="dataForm.housesImg" placeholder="缩略图"></el-input>
    </el-form-item>
    <el-form-item label="看房视频" prop="housesVideo">
      <el-input v-model="dataForm.housesVideo" placeholder="看房视频"></el-input>
    </el-form-item>
    <el-form-item label="全景地址" prop="panoramaSite">
      <el-input v-model="dataForm.panoramaSite" placeholder="全景地址"></el-input>
    </el-form-item>
    <el-form-item label="楼盘介绍" prop="housesIntroduce">
      <el-input v-model="dataForm.housesIntroduce" placeholder="楼盘介绍"></el-input>
    </el-form-item>
    <el-form-item label="建筑类型" prop="housesArchitecture">
      <el-input v-model="dataForm.housesArchitecture" placeholder="建筑类型"></el-input>
    </el-form-item>
    <el-form-item label="产权年限" prop="housesAge">
      <el-input v-model="dataForm.housesAge" placeholder="产权年限"></el-input>
    </el-form-item>
    <el-form-item label="占地面积" prop="housesArea">
      <el-input v-model="dataForm.housesArea" placeholder="占地面积"></el-input>
    </el-form-item>
    <el-form-item label="建筑面积" prop="housesArchitectureArea">
      <el-input v-model="dataForm.housesArchitectureArea" placeholder="建筑面积"></el-input>
    </el-form-item>
    <el-form-item label="容积率" prop="housesPlot">
      <el-input v-model="dataForm.housesPlot" placeholder="容积率"></el-input>
    </el-form-item>
    <el-form-item label="绿化率" prop="housesAfforest">
      <el-input v-model="dataForm.housesAfforest" placeholder="绿化率"></el-input>
    </el-form-item>
    <el-form-item label="规划户数" prop="housesProject">
      <el-input v-model="dataForm.housesProject" placeholder="规划户数"></el-input>
    </el-form-item>
    <el-form-item label="车位情况" prop="housesStall">
      <el-input v-model="dataForm.housesStall" placeholder="车位情况"></el-input>
    </el-form-item>
    <el-form-item label="物业类型" prop="housesReal">
      <el-input v-model="dataForm.housesReal" placeholder="物业类型"></el-input>
    </el-form-item>
    <el-form-item label="物业公司" prop="housesProperty">
      <el-input v-model="dataForm.housesProperty" placeholder="物业公司"></el-input>
    </el-form-item>
    <el-form-item label="物业费" prop="housesPropertyfee">
      <el-input v-model="dataForm.housesPropertyfee" placeholder="物业费"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          housesId: 0,
          housesName: '',
          housesDistrict: '',
          housesPrice: '',
          housesTime: '',
          housesSort: '',
          housesStatic: '',
          housesProvince: '',
          housesCity: '',
          housesCounty: '',
          housesSand: '',
          housesSite: '',
          housesOpeningTime: '',
          housesPhone: '',
          developersName: '',
          housesRedpacket: '',
          developersSite: '',
          housesCheckTime: '',
          developersCertificate: '',
          developersCoordinate: '',
          housesDiscounts: '',
          fitmentId: '',
          marketId: '',
          typeId: '',
          featureId: '',
          recommendId: '',
          housesImg: '',
          housesVideo: '',
          panoramaSite: '',
          housesIntroduce: '',
          housesArchitecture: '',
          housesAge: '',
          housesArea: '',
          housesArchitectureArea: '',
          housesPlot: '',
          housesAfforest: '',
          housesProject: '',
          housesStall: '',
          housesReal: '',
          housesProperty: '',
          housesPropertyfee: ''
        },
        dataRule: {
          housesName: [
            { required: true, message: '楼盘名称不能为空', trigger: 'blur' }
          ],
          housesDistrict: [
            { required: true, message: '楼盘区域不能为空', trigger: 'blur' }
          ],
          housesPrice: [
            { required: true, message: '楼盘价格不能为空', trigger: 'blur' }
          ],
          housesTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          housesSort: [
            { required: true, message: '楼盘排序不能为空', trigger: 'blur' }
          ],
          housesStatic: [
            { required: true, message: '楼盘状态不能为空', trigger: 'blur' }
          ],
          housesProvince: [
            { required: true, message: '楼盘省份不能为空', trigger: 'blur' }
          ],
          housesCity: [
            { required: true, message: '楼盘城市不能为空', trigger: 'blur' }
          ],
          housesCounty: [
            { required: true, message: '楼盘区县不能为空', trigger: 'blur' }
          ],
          housesSand: [
            { required: true, message: '楼盘沙盘不能为空', trigger: 'blur' }
          ],
          housesSite: [
            { required: true, message: '楼盘地址不能为空', trigger: 'blur' }
          ],
          housesOpeningTime: [
            { required: true, message: '楼盘开盘时间不能为空', trigger: 'blur' }
          ],
          housesPhone: [
            { required: true, message: '售楼电话不能为空', trigger: 'blur' }
          ],
          developersName: [
            { required: true, message: '开发商不能为空', trigger: 'blur' }
          ],
          housesRedpacket: [
            { required: true, message: '购房红包不能为空', trigger: 'blur' }
          ],
          developersSite: [
            { required: true, message: '售楼处地址不能为空', trigger: 'blur' }
          ],
          housesCheckTime: [
            { required: true, message: '交房时间不能为空', trigger: 'blur' }
          ],
          developersCertificate: [
            { required: true, message: '销售证号不能为空', trigger: 'blur' }
          ],
          developersCoordinate: [
            { required: true, message: '地图坐标不能为空', trigger: 'blur' }
          ],
          housesDiscounts: [
            { required: true, message: '是否优惠不能为空', trigger: 'blur' }
          ],
          fitmentId: [
            { required: true, message: '装修情况id不能为空', trigger: 'blur' }
          ],
          marketId: [
            { required: true, message: '销售状态不能为空', trigger: 'blur' }
          ],
          typeId: [
            { required: true, message: '类型id不能为空', trigger: 'blur' }
          ],
          featureId: [
            { required: true, message: '特色id不能为空', trigger: 'blur' }
          ],
          recommendId: [
            { required: true, message: '推荐id不能为空', trigger: 'blur' }
          ],
          housesImg: [
            { required: true, message: '缩略图不能为空', trigger: 'blur' }
          ],
          housesVideo: [
            { required: true, message: '看房视频不能为空', trigger: 'blur' }
          ],
          panoramaSite: [
            { required: true, message: '全景地址不能为空', trigger: 'blur' }
          ],
          housesIntroduce: [
            { required: true, message: '楼盘介绍不能为空', trigger: 'blur' }
          ],
          housesArchitecture: [
            { required: true, message: '建筑类型不能为空', trigger: 'blur' }
          ],
          housesAge: [
            { required: true, message: '产权年限不能为空', trigger: 'blur' }
          ],
          housesArea: [
            { required: true, message: '占地面积不能为空', trigger: 'blur' }
          ],
          housesArchitectureArea: [
            { required: true, message: '建筑面积不能为空', trigger: 'blur' }
          ],
          housesPlot: [
            { required: true, message: '容积率不能为空', trigger: 'blur' }
          ],
          housesAfforest: [
            { required: true, message: '绿化率不能为空', trigger: 'blur' }
          ],
          housesProject: [
            { required: true, message: '规划户数不能为空', trigger: 'blur' }
          ],
          housesStall: [
            { required: true, message: '车位情况不能为空', trigger: 'blur' }
          ],
          housesReal: [
            { required: true, message: '物业类型不能为空', trigger: 'blur' }
          ],
          housesProperty: [
            { required: true, message: '物业公司不能为空', trigger: 'blur' }
          ],
          housesPropertyfee: [
            { required: true, message: '物业费不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.housesId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.housesId) {
            this.$http({
              url: this.$http.adornUrl(`/backstage/houses/info/${this.dataForm.housesId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.housesName = data.houses.housesName
                this.dataForm.housesDistrict = data.houses.housesDistrict
                this.dataForm.housesPrice = data.houses.housesPrice
                this.dataForm.housesTime = data.houses.housesTime
                this.dataForm.housesSort = data.houses.housesSort
                this.dataForm.housesStatic = data.houses.housesStatic
                this.dataForm.housesProvince = data.houses.housesProvince
                this.dataForm.housesCity = data.houses.housesCity
                this.dataForm.housesCounty = data.houses.housesCounty
                this.dataForm.housesSand = data.houses.housesSand
                this.dataForm.housesSite = data.houses.housesSite
                this.dataForm.housesOpeningTime = data.houses.housesOpeningTime
                this.dataForm.housesPhone = data.houses.housesPhone
                this.dataForm.developersName = data.houses.developersName
                this.dataForm.housesRedpacket = data.houses.housesRedpacket
                this.dataForm.developersSite = data.houses.developersSite
                this.dataForm.housesCheckTime = data.houses.housesCheckTime
                this.dataForm.developersCertificate = data.houses.developersCertificate
                this.dataForm.developersCoordinate = data.houses.developersCoordinate
                this.dataForm.housesDiscounts = data.houses.housesDiscounts
                this.dataForm.fitmentId = data.houses.fitmentId
                this.dataForm.marketId = data.houses.marketId
                this.dataForm.typeId = data.houses.typeId
                this.dataForm.featureId = data.houses.featureId
                this.dataForm.recommendId = data.houses.recommendId
                this.dataForm.housesImg = data.houses.housesImg
                this.dataForm.housesVideo = data.houses.housesVideo
                this.dataForm.panoramaSite = data.houses.panoramaSite
                this.dataForm.housesIntroduce = data.houses.housesIntroduce
                this.dataForm.housesArchitecture = data.houses.housesArchitecture
                this.dataForm.housesAge = data.houses.housesAge
                this.dataForm.housesArea = data.houses.housesArea
                this.dataForm.housesArchitectureArea = data.houses.housesArchitectureArea
                this.dataForm.housesPlot = data.houses.housesPlot
                this.dataForm.housesAfforest = data.houses.housesAfforest
                this.dataForm.housesProject = data.houses.housesProject
                this.dataForm.housesStall = data.houses.housesStall
                this.dataForm.housesReal = data.houses.housesReal
                this.dataForm.housesProperty = data.houses.housesProperty
                this.dataForm.housesPropertyfee = data.houses.housesPropertyfee
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/backstage/houses/${!this.dataForm.housesId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'housesId': this.dataForm.housesId || undefined,
                'housesName': this.dataForm.housesName,
                'housesDistrict': this.dataForm.housesDistrict,
                'housesPrice': this.dataForm.housesPrice,
                'housesTime': this.dataForm.housesTime,
                'housesSort': this.dataForm.housesSort,
                'housesStatic': this.dataForm.housesStatic,
                'housesProvince': this.dataForm.housesProvince,
                'housesCity': this.dataForm.housesCity,
                'housesCounty': this.dataForm.housesCounty,
                'housesSand': this.dataForm.housesSand,
                'housesSite': this.dataForm.housesSite,
                'housesOpeningTime': this.dataForm.housesOpeningTime,
                'housesPhone': this.dataForm.housesPhone,
                'developersName': this.dataForm.developersName,
                'housesRedpacket': this.dataForm.housesRedpacket,
                'developersSite': this.dataForm.developersSite,
                'housesCheckTime': this.dataForm.housesCheckTime,
                'developersCertificate': this.dataForm.developersCertificate,
                'developersCoordinate': this.dataForm.developersCoordinate,
                'housesDiscounts': this.dataForm.housesDiscounts,
                'fitmentId': this.dataForm.fitmentId,
                'marketId': this.dataForm.marketId,
                'typeId': this.dataForm.typeId,
                'featureId': this.dataForm.featureId,
                'recommendId': this.dataForm.recommendId,
                'housesImg': this.dataForm.housesImg,
                'housesVideo': this.dataForm.housesVideo,
                'panoramaSite': this.dataForm.panoramaSite,
                'housesIntroduce': this.dataForm.housesIntroduce,
                'housesArchitecture': this.dataForm.housesArchitecture,
                'housesAge': this.dataForm.housesAge,
                'housesArea': this.dataForm.housesArea,
                'housesArchitectureArea': this.dataForm.housesArchitectureArea,
                'housesPlot': this.dataForm.housesPlot,
                'housesAfforest': this.dataForm.housesAfforest,
                'housesProject': this.dataForm.housesProject,
                'housesStall': this.dataForm.housesStall,
                'housesReal': this.dataForm.housesReal,
                'housesProperty': this.dataForm.housesProperty,
                'housesPropertyfee': this.dataForm.housesPropertyfee
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
